package com.easy.controller;

import com.easy.bean.Book;
import com.easy.service.BookService;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("book")
public class BookController {

    @Autowired
    BookService bookService;

    @PostMapping
    public Result add(@RequestBody Book book){
        Object obj=bookService.add(book);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Book book){
        Object obj=bookService.edit(book);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj=bookService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj=bookService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Book book){
        Object obj=bookService.all(book);
        return Result.success(obj);
    }

    @GetMapping("/page")
    public Result page(com.easy.util.Page page,Book book){
        bookService.page(page,book);
        return Result.success(page);
    }
}
